package com.zzptc.lxy.mybook.ui.notifications;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.zzptc.lxy.mybook.AboutActivity;
import com.zzptc.lxy.mybook.LoginActivity;
import com.zzptc.lxy.mybook.MedalActivity;
import com.zzptc.lxy.mybook.NoteActivity;
import com.zzptc.lxy.mybook.NoticeActivity;
import com.zzptc.lxy.mybook.PersonalActivity;
import com.zzptc.lxy.mybook.R;
import com.zzptc.lxy.mybook.ReadLogActivity;
import com.zzptc.lxy.mybook.SettingsActivity;
import com.zzptc.lxy.mybook.TopActivity;

public class NotificationsFragment extends Fragment {
    private TextView usertxt;
    private LinearLayout Lv_wode, Lv_top, Lv_medal, Lv_note, Lv_ReadingLog, Lv_about, Lv_quit;
    private ImageView settings_img, notice_img;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_notifications, container, false);
        initView(view);
        setListener();
        return view;
    }

    private void setListener() {
//        跳转到个人信息页面
        Lv_wode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), PersonalActivity.class));
            }
        });
//        跳转到设置页面
        settings_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), SettingsActivity.class));

            }
        });
//        信息页面
        notice_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), NoticeActivity.class));
            }
        });


//        跳转到排行榜页面
        Lv_top.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), TopActivity.class));
            }
        });
//勋章
        Lv_medal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), MedalActivity.class));
            }
        });
//        笔记页面
        Lv_note.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), NoteActivity.class));


            }
        });
//        阅读记录
        Lv_ReadingLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), ReadLogActivity.class));
            }
        });
//        关于页面
        Lv_about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), AboutActivity.class));
            }
        });
//        退出登录
        Lv_quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), LoginActivity.class));
            }
        });
    }

    private void initView(View v) {
        usertxt = v.findViewById(R.id.usertxt);
        Lv_wode = v.findViewById(R.id.Lv_wode);
        Lv_top = v.findViewById(R.id.Lv_top);
        Lv_medal = v.findViewById(R.id.Lv_medal);
        Lv_note = v.findViewById(R.id.Lv_note);
        Lv_ReadingLog = v.findViewById(R.id.Lv_ReadingLog);
        Lv_about = v.findViewById(R.id.Lv_about);
        Lv_quit = v.findViewById(R.id.Lv_quit);
        notice_img = v.findViewById(R.id.notice_img);
        settings_img = v.findViewById(R.id.settings_img);


        SharedPreferences sp = getActivity().getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        int uid = sp.getInt("userid", -1);
        String usn = sp.getString("username", "");
//        usertxt.setText("你好，"+uid+"号用户"+usn);
        usertxt.setText(usn);

    }
}